<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">

            <h:form>
                <p:commandButton action="#{customerEntityController.prepareCreate}" rendered="#{loginBacking.addCustomer}" ajax="false" value="Create New Customer"/>
                <p:commandButton action="/entities/customerEntity/Search.xhtml" ajax="false" value="Search for customer"/>
            
            </h:form>
            <br/>

            <h:form prependId="false">

                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <h:outputText escape="false" value="#{bundle.ListCustomerEntityEmpty}" rendered="#{customerEntityController.items.rowCount == 0}"/>

                <p:panel toggleable="true" id="customerList" header="Customers" rendered="#{customerEntityController.items.rowCount > 0}">
                    <p:dataTable value="#{customerEntityController.items}" 
                                 var="item"  
                                 style="table-layout:fixed" paginator="true" rows="10"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15">  
                        <p:column filterBy="#{item.id}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerEntityTitle_id}"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>
                        <p:column filterBy="#{item.name}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerEntityTitle_name}"/>
                            </f:facet>
                            <h:outputText value="#{item.name}"/>
                        </p:column>
                        <p:column filterBy="#{item.companyName}">
                            <f:facet name="header">
                                <h:outputText value="Company"/>
                            </f:facet>
                            <h:outputText value="#{item.companyName}"/>
                        </p:column>

                        <p:column filterBy="#{item.customerExecutive.fullname}">
                            <f:facet name="header">
                                <h:outputText value="Customer Executive"/>
                            </f:facet>
                            <h:outputText value="#{item.customerExecutive.fullname}"/>
                        </p:column>
                        
                        <p:column filterBy="#{item.customerType}">
                            <f:facet name="header">
                                <h:outputText value="Customer Type"/>
                            </f:facet>
                            <h:outputText value="#{item.customerType}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Customer Account"/>
                            </f:facet>
                            <h:commandLink action="/entities/customerAccountEntity/View.xhtml" value="View Account" rendered="#{item.hasAccount}">
                                <f:setPropertyActionListener target="#{customerEntityController.current}" value="#{item}" />
                                <f:setPropertyActionListener target="#{customerAccountEntityController.current}" value="#{item.customerAccount}" />
                                <f:setPropertyActionListener target="#{creditTermEntityController.current}" value="#{item.customerAccount.creditTerm}" />
                            </h:commandLink>
                            <h:outputText value="Not Assigned" rendered="#{!item.hasAccount}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListSalesLeadEntityTitle_isArchived}"/>
                            </f:facet>
                            <h:outputText value= "Archived" rendered="#{item.archived==true}"/>
                            <h:outputText value= "Active" rendered="#{item.archived==false}"/>
                        </p:column>



                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:commandButton image="ui-icon ui-icon-search" update="display" oncomplete="customerDialog.show()">
                                <f:setPropertyActionListener value="#{item}"  
                                                             target="#{customerEntityController.customer}" /> 
                            </p:commandButton>
                        </p:column>

                        <p:column rendered="#{loginBacking.editCustomer or loginBacking.deleteCustomer}">  
                            <p:menuButton value="Options">       
                                <p:menuitem value=" Edit" ajax="false" icon="ui-icon ui-icon-disk" 
                                            action="#{customerEntityController.prepareEdit}" rendered="#{loginBacking.editCustomer}"/>
                                <p:menuitem value=" Delete" ajax="false" rendered="#{item.archived==false and loginBacking.deleteCustomer}" icon="ui-icon ui-icon-close"
                                            action="#{customerEntityController.destroy}"/>        
                            </p:menuButton>    
                        </p:column>

                    </p:dataTable>

                    <p:dialog header="Customer Detail" widgetVar="customerDialog" resizable="false"  
                              width="325" showEffect="explode" hideEffect="explode">  

                        <h:panelGrid id="display" columns="2" cellpadding="4">  

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_companyName}"/>
                            <h:outputText value="#{customerEntityController.customer.companyName}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_jobTitle}"/>
                            <h:outputText value="#{customerEntityController.customer.jobTitle}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_customerAccount}"/>
                            <h:outputText value="#{customerEntityController.customer.customerAccount}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_customerExecutive}"/>
                            <h:outputText value="#{customerEntityController.customer.customerExecutive.firstName}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_name}"/>
                            <h:outputText value="#{customerEntityController.customer.name}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_firstName}"/>
                            <h:outputText value="#{customerEntityController.customer.firstName}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_lastName}"/>
                            <h:outputText value="#{customerEntityController.customer.lastName}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_title}"/>
                            <h:outputText value="#{customerEntityController.customer.title}"/>

                            <h:outputText value="Contact Number: "/>
                            <h:outputText value="#{customerEntityController.customer.contact.contactNumber}"/>

                            <h:outputText value="Customer Type: "/>
                            <h:outputText value="#{customerEntityController.customer.customerType}"/>

                            <h:outputText value="Email"/>
                            <h:outputText value="#{customerEntityController.customer.contact.email}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_id}"/>
                            <h:outputText value="#{customerEntityController.customer.id}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_createdAt}"/>
                            <h:outputText value="#{customerEntityController.customer.createdAt}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_createdBy}"/>
                            <h:outputText value="#{customerEntityController.customer.createdBy.firstName}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_lastModifiedAt}"/>
                            <h:outputText value="#{customerEntityController.customer.lastModifiedAt}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_lastModifiedBy}"/>
                            <h:outputText value="#{customerEntityController.customer.lastModifiedBy.firstName}"/>

                            <h:outputText value="#{bundle.ListCustomerEntityTitle_isArchived}"/>
                            <h:outputText value= "Archived" rendered="#{customerEntityController.customer.archived==true}"/>
                            <h:outputText value= "Active" rendered="#{customerEntityController.customer.archived==false}"/>
                        </h:panelGrid>  
                    </p:dialog>  
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
